package main

import (
	"testing"
	"net/http"
	"net/http/httputil"
	"strings"
	"fmt"
	"log"
	"io/ioutil"
)

var (
	targetUrl="http://localhost:8888/sd/post"
	testJson =`
	[
	{
        "sd":"999999",
		"sd_type":"T",
		"env":"bthsjnl1",
		"tname":"PB0A"
	},
	{
        "sd":"88888",
		"sd_type":"F",
		"env":"bthsjnl1",
		"tname":"PB0A"
	}
	]
`
)




func testJsonControl(t *testing.T)  {
	c :=http.Client{}
	req,err :=http.NewRequest(http.MethodPost,targetUrl,strings.NewReader(testJson))
	if err != nil {
		t.Errorf("http method NewRequest Failture %s",err)
	}
	req.Header.Add("Content-Type","application/json")

	resp,err:=c.Do(req)
	if err != nil {
		t.Errorf("http Client method Do failture %s",err)
	}
	body,err:=httputil.DumpResponse(resp,false)
	fmt.Println(string(body))
}
func TestKV2(t *testing.T)  {
	c :=http.Client{}
	targetUrl:="http://localhost:8888/sd/kv"
	log.Println(targetUrl)
	kv :="k=application:x-www-form-urlencoded"
	req,err :=http.NewRequest(http.MethodPost,targetUrl,strings.NewReader(kv))
	if err != nil {
		t.Errorf("http method NewRequest Failture %s",err)
	}
	req.Header.Add("Content-Type","application/x-www-form-urlencoded")

	resp,err:=c.Do(req)
	if err != nil {
		t.Errorf("http Client method Do failture %s",err)
	}
	body,err:=ioutil.ReadAll(resp.Body)
	fmt.Println(string(body))
}
